package yxk.report.wtc.wtte;

import kd.bos.form.mcontrol.mobtable.MobTablePackageDataHandler;
import kd.bos.form.mcontrol.mobtable.MobTableRowBuilder;
import kd.bos.form.mcontrol.mobtable.MobTableRowData;
import kd.bos.form.mcontrol.mobtable.events.MobTableHandleResult;
import kd.bos.form.mcontrol.mobtable.events.MobTablePackageDataHandlerArgs;
import kd.bos.form.mcontrol.mobtable.tablecolumn.MobTableColumn;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class AttendanceInformatioDataHandler extends MobTablePackageDataHandler {
    private Map<String,Map<String,Map<String,String>>> exceMap;
    private Map<String, Map<String, List<Map<String, String>>>> maps;
    private String bles;

    public AttendanceInformatioDataHandler(){

    }
    public AttendanceInformatioDataHandler(Map<String,Map<String,Map<String,String>>> map,String  bes){
        this.exceMap = map;
        this.bles = bes;
    }

    public AttendanceInformatioDataHandler(String  bes,Map<String, Map<String, List<Map<String, String>>>> map){
        this.maps = map;
        this.bles = bes;
    }
    @Override
    public MobTableHandleResult handleData(MobTablePackageDataHandlerArgs args) {
       List<MobTableColumn> mobTableColumns = args.getMobTableColumns();
        MobTableHandleResult mobTableHandleResult = new MobTableHandleResult();
        List<MobTableRowData> mobTableRowDataList = new ArrayList<>();
        switch (bles) {
            case "0":
                int k=0;
                for (String row : maps.keySet()) {
                    Map<String, List<Map<String, String>>> userMap = maps.get(row);
                    List<String> dateList = userMap.keySet().stream().collect(Collectors.toList());
                    Collections.sort(dateList);
                    for (String key : dateList) {
                        List<Map<String, String>> mapList = userMap.get(key);
                        for (Map<String, String> valueMap : mapList) {
                            MobTableRowData mobTableRowData = MobTableRowBuilder.buildTemplateRowData(k, mobTableColumns);
                            mobTableRowData.setValue("name",valueMap.get("attperson"));
                            mobTableRowData.setValue("nwg5_date",key);
                            mobTableRowData.setValue("nwg5_mustpoint",valueMap.get("mustpoint"));
                            mobTableRowData.setValue("nwg5_effectivepoint",valueMap.get("effectivepoint"));
                            mobTableRowDataList.add(mobTableRowData);
                            k++;
                        }
                    }
                }
                break;
            case "1":
                int i = 0;
                for (String row : exceMap.keySet()) {
                    Map<String, Map<String, String>> personMap = exceMap.get(row);
                    List<String> keyList = personMap.keySet().stream().collect(Collectors.toList());
                    Collections.sort(keyList);
                    for (String key : keyList) {
                        Map<String, String> map = personMap.get(key);
                        //生成行中数据
                        MobTableRowData mobTableRowData = MobTableRowBuilder.buildTemplateRowData(i, mobTableColumns);
                       // mobTableRowData.getRow().clear();
                        mobTableRowData.setValue("nwg5_name", map.get("name"));
                        mobTableRowData.setValue("nwg5_recorddate", map.get("recordDate"));

                        String EX_1010_S = map.get("EX_1010_S");//迟到时长
                        if (EX_1010_S != null && !"".equals(EX_1010_S)) {
                            mobTableRowData.setValue("nwg5_belate", EX_1010_S + "(分钟)");//迟到时长
                        }

                        String EX_1020_S = map.get("EX_1020_S");//早退时长
                        if (EX_1020_S != null && !"".equals(EX_1020_S)) {
                            mobTableRowData.setValue("nwg5_leaveearly", EX_1020_S + "(分钟)");//早退时长
                        }

                        String RE_1030_S = map.get("RE_1030_S");//缺卡次数
                        if (RE_1030_S != null && !"".equals(RE_1030_S)) {
                            mobTableRowData.setValue("nwg5_lackofcards", RE_1030_S + "(次)");//缺卡次数
                        }
                        String EX_1140_S = map.get("EX_1140_S");//旷工天数
                        if (EX_1140_S != null && !"".equals(EX_1140_S)) {
                            mobTableRowData.setValue("nwg5_absenteeism", EX_1140_S + "(天)");//旷工天数
                        }
                        String OR_1030_S = map.get("OR_1030_S");//出差时长
                        if (OR_1030_S != null && !"".equals(OR_1030_S)) {
                            mobTableRowData.setValue("nwg5_business", OR_1030_S + "(小时)");//出差时长
                        }
                        String OR_1040_S = map.get("OR_1040_S");//休假时长
                        if (OR_1040_S != null && !"".equals(OR_1040_S)) {
                            mobTableRowData.setValue("nwg5_holiday", OR_1040_S + "(小时)");//休假时长
                        }
                        mobTableRowDataList.add(mobTableRowData);
                        i++;
                    }

                }
                break;
        }
        mobTableHandleResult.setMobTableRowDataList(mobTableRowDataList);
        mobTableHandleResult.setFmtInfo(getFmtInfo(args));
        return mobTableHandleResult;
    }
}
